package cf.huzpsb.bcgod;

import net.md_5.bungee.api.CommandSender;
import net.md_5.bungee.api.connection.ProxiedPlayer;
import net.md_5.bungee.api.plugin.Command;

import java.util.Iterator;

public class BanCMD extends Command {
    public BanCMD(String name, String permission, String... aliases) {
        super(name, permission, aliases);
    }

    public void execute(CommandSender sender, String[] args) {
        if (!(sender instanceof ProxiedPlayer)) {
            sender.sendMessage("§c后台不推荐使用此命令");
        } else if (((ProxiedPlayer) sender).getServer().getInfo().getName().equalsIgnoreCase(Main.login)) {
            sender.sendMessage("§c登录区域禁止使用!");
            return;
        }
        if (args.length != 1) {
            sender.sendMessage("§c参数错误");
        } else {
            String st = args[0].replace(".", "D");
            if (!Main.bancfg.contains(st)) {
                Main.bancfg.set(st, "T");
                sender.sendMessage("§a封禁成功!");
            } else {
                sender.sendMessage("§c玩家已经被封禁!禁止重复封禁!");
                return;
            }
            Iterator var17 = Main.getInstance().getProxy().getPlayers().iterator();

            while (var17.hasNext()) {
                ProxiedPlayer player1 = (ProxiedPlayer) var17.next();
                if (player1.getName().equalsIgnoreCase(args[0]) || player1.getAddress().getAddress().getHostAddress().equals(args[0])) {
                    player1.disconnect("§cOops...");
                    return;
                }
            }
            sender.sendMessage("§c警告:玩家不在线!");
        }
    }
    //config.set(args[0], (Object)null);
}
